import sys
from dingtalkchatbot.chatbot import DingtalkChatbot
from dingtalkchatbot.chatbot import CardItem
from dingtalkchatbot.chatbot import ActionCard
# WebHook地址
#webhook = 'https://oapi.dingtalk.com/robot/send?access_token=02fd5264b64d3907ec768ad1b133f739cb5720e7e90148d4e6ca37cf34a83a94'
#xiaoding = DingtalkChatbot(webhook) 

# ActionCard独立跳转消息类型
# macdown   支持@对应人+跳转所以选择macdown发送
status = sys.argv[1]
project_name = sys.argv[2]
server_name = sys.argv[3]
env_name = sys.argv[4]
build_num = sys.argv[5]

if len(sys.argv) == 7:
    webhook = sys.argv[6]
else:
    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=02fd5264b64d3907ec768ad1b133f739cb5720e7e90148d4e6ca37cf34a83a94'

xiaoding = DingtalkChatbot(webhook)

#at_mobiles=[Mobiles]
xiaoding.send_markdown(title='wethink', text='jenkins更新通知'+'\n'
                    '> 项目:'+project_name+'\n\n'
                    '> 环境:'+env_name+'\n\n'
                    '> 服务:'+server_name+'\n\n'
                    '> 状态:'+status+'\n\n'
                    '> 编号:'+build_num+'\n\n'
                    )